{{#google_drive_key}}
	<script type="text/javascript">
	$('.upload-corral').hide();

	// Create and render a Picker object for searching images.
	function createPicker() {
		var view = new google.picker.DocsView()
			.setParent('root')
			.setIncludeFolders(true);
		var uploadview = new google.picker.DocsUploadView();
		var picker = new google.picker.PickerBuilder()
			.enableFeature(google.picker.Feature.MINE_ONLY)
			.disableFeature(google.picker.Feature.NAV_HIDDEN)
			.disableFeature(google.picker.Feature.MULTISELECT_ENABLED)
			.setAppId('{{google_drive_app_id}}')
			.setAuthUser('{{connection_auth_user}}')
			.setOAuthToken('{{connection_auth_token}}') //Optional: The auth token used in the current Drive API session.
			.addView(uploadview)
			.addView(view)
			.setCallback(pickerCallback)
			.build();
		picker.setVisible(true);

		// move the dialog to the right place
		$('.picker-dialog').css('overflow','hidden'); // firefox shows a scrollbar. dunno? this fixes
		$('.picker-dialog').css('z-index',98765);
		$('.picker-dialog').blur();
	}

	function pickerCallback(data) {
		if (data.action == google.picker.Action.PICKED) {
			var fileId = data.docs[0].id;
			$('#asset_location').val(fileId);
			// IF PARENT FORM HAS .autosubmit then submit that shit
	      var parentForm = $('#asset_location').closest('form');
	      if (parentForm.hasClass('autosubmit')) {
	         parentForm.submit();
	      }
		}
	}

	google.load('picker','1',{'callback': createPicker});
	</script>
{{/google_drive_key}}
{{^google_drive_key}}
	{{copy_choose_connection}}
{{/google_drive_key}}
